home *** CD-ROM | disk | FTP | other *** search
/ Chip 1999 November / Chip_1999-11_cd.bin / zkuste / MacOS / DATA / FILES / POWER64.HQX / Power64 2.5.1 / Power64 2.5.1 - Read Me.rsrc / TEXT_138.txt < prev    next >
Text File  |  1999-09-20  |  14KB  |  417 lines

  1. Appendix A : Commodore 64 BASIC V2 Summary
  2.  
  3. Here is a short summary of the commands for the built in Commodore 64 BASIC V2. Note that this is not intended to be a tutorial, but just a quick reference to refresh long unused brain cells.
  4.  
  5. In C64 BASIC V2 there are only few types of variables:
  6. ΓÇó Float: This is the most frequently used type. Float-variables do not carry a type identifier.
  7.           Range +/- [2.94E-39 ... 1.70E+38] (+/- [2^-128 ... 2^127])
  8.           Precision: 32 bit (approx. 9.6 decimal digits)
  9. ΓÇó Integer (16 Bit): This is a rarely used type. Integer variables carry a '%' at the end of their name (eg. X%). Note that all computations are performed with float precision and conversion to Integer is only performed when the value is assigned to a variable. Thus Integer math is SLOWER (!) than Float math.
  10.  ΓÇó Boolean Results are expressed using Integers. FALSE is represented by 0 (0x0000) and TRUE by -1 (0xFFFF) or any other non-zero value.
  11. ΓÇó Strings: String variables carry a '$' at the end of their name (eg. X$). Strings can be at most 255 characters long.
  12.  
  13. Only the first TWO (!) characters of a variable name are significant.
  14.  
  15. Program Flow Control:
  16.  
  17. FOR...TO...STEP...NEXT - The only real loop construct in BASIC
  18.   Syntax: FOR <Var> = <Start> TO <End> [STEP <Size>]
  19.             <Loop Code>
  20.           NEXT [<Var>]
  21.   Examples: FOR I=1 TO 5: PRINT I;: NEXT           -> 1 2 3 4 5
  22.           FOR I=1 TO 5 STEP  2: PRINT I;: NEXT   -> 1 3 5
  23.           FOR I=5 TO 1 STEP -2: PRINT I;: NEXT I -> 5 3 1
  24.           FOR I=3 TO 1: PRINT I;: NEXT           -> 3 (!)
  25.  
  26. IF...THEN - Conditional Program Execution
  27.   Note: There is no such thing as ELSE or ENDIF.
  28.   Syntax: IF <Condition> THEN <Statements>
  29.          or  IF <Condition> GOTO <LineNr>
  30.          or   IF <Condition> THEN <LineNr>
  31.   Example: 100 IF A < B THEN MN = A: GOTO 120
  32.          110 MN = B
  33.          120 ....
  34.  
  35. GOTO or GO TO - Unconditional Jump
  36.   Syntax: GOTO <LineNr>
  37.          or   GO TO <LineNr>
  38.  
  39. GOSUB - Unconditional Jump to Subroutine
  40.   Note that it is not possible to use formal parameters to a subroutine.
  41.   Everything must be done using global variables.
  42.   Syntax: GOSUB <LineNr>
  43.   Example: 10 PRINT "Main Program"
  44.          20 GOSUB 100
  45.          30 PRINT "Back To Main"
  46.                   40 GOSUB 100
  47.          50 PRINT "Once again Main"
  48.          60 END
  49.         100 PRINT "This is the Subroutine"
  50.         110 RETURN
  51.  
  52. RETURN - Return from Subroutine
  53.   Syntax: RETURN
  54.   Example: See GOSUB
  55.  
  56. ON...GOTO or ON...GOSUB - Multiway branch
  57.   Syntax: ON <IntegerExpr> GOTO <LineNr1>, <LineNr2> ...
  58.     or         ON <IntegerExpr> GOSUB <LineNr1>, <LineNr2> ...
  59.   Example: ON X GOTO 100, 200, 300
  60.     This is equivalent to:
  61.                IF X = 1 THEN GOTO 100
  62.          IF X = 2 THEN GOTO 200
  63.          IF X = 3 THEN GOTO 300
  64.  
  65. DEF FN - Define a BASIC Function/Subroutine
  66.   Syntax: DEF FN <Name>(<Param>) = <Single Line Expression>
  67.   Example: DEF FN SI(X) = SIN(X)/X
  68.          FN SI(╧Ç/3) -> 0.816993343
  69.  
  70.  
  71. Input/Output:
  72.  
  73. GET - Read One Character from Standard Input without waiting
  74.   Syntax: GET <VarName>
  75.   Example: 100 GET A$: IF A$ = "" THEN GOTO 100 -> Wait for any Key
  76.  
  77. INPUT - Get Data from Standard Input (usually Keyboard)
  78.   Syntax: INPUT [<Prompt>;] <VarName> [, <VarName> ...]
  79.   Examples: INPUT "LOGIN:"; LG$
  80.           INPUT "Please Enter A, B and C"; A, B, C
  81.           INPUT A
  82.  
  83. PRINT - Write to Standard Output (usually Screen)
  84.   Syntax: PRINT <Data>
  85.       or:     ? <Data>
  86.   Examples: PRINT "Hello World"
  87.           PRINT "Here", "are", "Tabs"  -> Note the ','
  88.           PRINT "First Line";          -> Note the ';'
  89.           PRINT "Still the same line"
  90.           PRINT "Power"; 2*32
  91.  
  92. SPC - Advance the Cursor by a specific Number of Steps
  93.   Syntax: SPC(<Cnt>)
  94.   Example: SPC(6)
  95.  
  96. TAB - Advance the Cursor to a Specific Position
  97.   Syntax: TAB(<Place>)
  98.   Example: TAB(6)
  99.  
  100. POS - Current Cursor Position
  101.   Syntax: POS(<Dummy>)
  102.  
  103.  
  104. Files:
  105.  
  106. LOAD - Load a Program from Disk or Tape
  107.   Syntax: LOAD <FileName> [, <Device> [, <SecondDev>]]
  108.   Example: LOAD "SuperGame", 8, 1 -> Absolute Load from Disk #8
  109.          LOAD "*", 9 -> Load the first program from Disk #9
  110.          LOAD "", 1  -> Load the first program from Tape (#1)
  111.  
  112. SAVE - Save a Program to Disk or Tape
  113.   Syntax: SAVE <FileName> [, <Device> [, <SecondDev>]]
  114.   Example: SAVE "SuperGame", 8 -> Save to Disk #8
  115.  To overwrite an existing file on a disk, prefix the filename with '@'
  116.   Example: SAVE "@SuperGame",8  -> Save to Disk #8, overwriting an old  file 
  117.  
  118. VERIFY - Check if the Program in Memory and a Program on Disk or Tape are equal. Do not modify anything.
  119.   Syntax: VERIFY <FileName> [, <Device> [, <SecondDev>]]
  120.   Example: VERIFY "SuperGame", 8 -> Check SuperGame from Disk #8
  121.          VERIFY "*", 9 -> Check the first program from Disk #9
  122.          VERIFY "", 1  -> Check the first program from Tape #1
  123.  
  124. OPEN - Open a File
  125.   Syntax: OPEN <FileID>, <Device> [, <SecondDev> [, <FNameMode>]]
  126.  The <SecondDev> is an optional integer in the range 0-15 with the following meaning: 0..Used for LOAD, 1..Used for SAVE, 2-14..Freely usable for User File Access, 15..Command/Error Channel.
  127.     <FNameMode> uses the format: "<FileName> [,<FileType> [,<AccessMode>]]" where <FileType> is one of P (Program), S (Sequential), L (Relative) or U (User) and <AccessMode> is one of R (Read), W (Write), A (Append) or the number of Bytes/Record for Relative Files.
  128.   Example: OPEN 1, 4      -> Open a Output File to the Printer #4
  129.          OPEN 1, 8, 2, "My File,P,R" -> Open a Program for Reading
  130.          OPEN 1, 8, 2, "My File,S,W" -> Open a Sequential File for Writing
  131.          OPEN 1, 8, 2, "My File,L,"+CHR$(40) -> Open a Relative File with 40 Bytes/Record
  132.          OPEN 1, 8, 15 -> Open the Disk Command/Error Channel
  133.  
  134. CLOSE - Close a File
  135.   Syntax: CLOSE <FileID>
  136.   Example: CLOSE 1
  137.  
  138. GET# - Read One Character from a File
  139.   Syntax: GET# <FileID>, <VarName>
  140.   Example: GET#1, A$
  141.   Note that there is no space between 'GET' and '#'.
  142.  
  143. INPUT# - Get Data from a File
  144.   Syntax: INPUT# <FileID>, <VarName> [, <VarName>...]
  145.   Example: INPUT#1, EN$, ER$, TR$, SC$
  146.   Note that there is no space between 'INPUT' and '#'.
  147.  
  148. PRINT#
  149.   Syntax: PRINT# <FileID>, <Data>
  150.   Example: PRINT#1, "Power64"
  151.   Note that there is no space between 'PRINT' and '#'. Note also that
  152.   ?# is not PRINT# also they look the same in a listing.
  153.  
  154. CMD - Redirect Standard Output (Input is not affected) and writes a
  155.       Message to it
  156.   Syntax: CMD <FileID> [, <Message>]
  157.   Example: OPEN 1, 4           ; Open a File#1 on Printer#4 
  158.          CMD 1               ; Make it the standard Output
  159.          PRINT "Whatever Output you want"
  160.          PRINT "More Output"
  161.          PRINT#1             ; Undo CMD 1
  162.          CLOSE 1
  163.  
  164. ST - Device Status (Built-In Variable)
  165.   ST = 0 .. Device Ok
  166.   Bit 6: 1 .. End of File
  167.   Bit 7: 1 .. Device Not Present
  168.  
  169. READ - Read Static Data from DATA Statements in the Program
  170.   Syntax: READ <Var> [, <Var>...]
  171.   Example: 10 RESTORE
  172.          20 READ X$
  173.          30 PRINT X$;
  174.          40 S = 0
  175.          50 FOR I=1 TO 3
  176.          60 READ X
  177.          70 S = S + X
  178.          80 NEXT I
  179.          90 PRINT S
  180.         100 DATA "Power", 12, 34, 18
  181.  
  182. RESTORE - Set Pointer to Next DATA element to the first DATA statement
  183.   in the program.
  184.   Syntax: RESTORE
  185.   Example: See READ
  186.  
  187. DATA - Store Static Data
  188.   Syntax: DATA <Data> [, <Data>...]
  189.   Example: See READ
  190.  
  191.  
  192. Math Functions:
  193.  
  194. LET - Assignment
  195.   Syntax: LET <Variable> = <Value>
  196.   Example LET A = 6.25
  197.   Note the LET keyword is not necessary. <Variable> = <Value> is all
  198.   that is needed. LET only slows things down -> Don't use it!
  199.  
  200. DIM - Array Declaration
  201.   Syntax: DIM <Name>(<Size> [, <Size>...])
  202.   Example: DIM A(7)   -> An array of 8(!) elements indexed [0..7]
  203.                   DIM B$(4,5) -> An array of 30(!) strings
  204.   Usage of Elements: A(3) = 17 : B$(2,3) = "Power64"
  205.  
  206. +, -, *, / - Arithmetic Operators
  207.   Example: 9 + 5 * (15 - 1) / 7 -> 19
  208.  
  209. <, <=, =, <>, >=, > - Comparison Operators
  210.   Examples: 3 <> 6  -> -1 (TRUE)
  211.                    3 > 4   -> 0  (FALSE)
  212.  
  213. SIN - Sine (Argument in Radians)
  214.   Syntax: SIN(<Value>)
  215.   Example: SIN(╧Ç/3) -> 0.866025404
  216.  
  217. COS - Cosine (Argument in Radians)
  218.   Syntax: COS(<Value>)
  219.   Example: COS(╧Ç/3) -> 0.5
  220.  
  221. TAN - Tangent (Argument in Radians)
  222.   Syntax: TAN(<Value>)
  223.   Example: TAN(╧Ç/3) -> 1.73205081
  224.  
  225. ATN - Arcus Tangent (Result in [-╧Ç/2 .. ╧Ç/2])
  226.   Syntax: ATN(<Value>)
  227.   Example: ATN(1) -> 0.785398163 ( = ╧Ç/4)
  228.  
  229. EXP - Exponent (E^X where E = 2.71828183...)
  230.   Syntax: EXP(<Value>)
  231.   Example: EXP(6.25) -> 518.012825
  232.  
  233. LOG - Natural Logarithm
  234.   Syntax: LOG(<Value>)
  235.   Example: LOG(6.25) -> 1.83258146
  236.  
  237. SQR - Square Root
  238.   Syntax: SQR(<Value>)
  239.   Example: SQR(6.25) -> 2.5
  240.  
  241. ABS - Absolute Value
  242.   Syntax: ABS(<Value>)
  243.   Examples: ABS(-6.25) -> 6.25
  244.           ABS(0)     -> 0
  245.           ABS(6.25)  -> 6.25
  246.  
  247. SGN - Sign
  248.   Syntax: SGN(<Value>)
  249.   Examples: SGN(-6.25) -> -1
  250.           SGN(0)     ->  0
  251.           SGN(6.25)  ->  1
  252.  
  253. INT - Integer (Truncate to greatest integer less or equal to Argument.)
  254.   Syntax: INT(<Value>)
  255.   Examples: INT(-6.25) -> -7 (!)
  256.           INT(-5)    -> -5
  257.           INT(0)     ->  0
  258.           INT(5)     ->  5
  259.           INT(6.25)  ->  6
  260.  
  261. RND - Random Number in [0.0 .. 1.0]
  262.   Syntax: RND(<Seed>)
  263.   If (<Seed> < 0) the Random number generator is initialized
  264.   Examples: RND(-625) -> 3.85114436E-06
  265.           RND(0)    -> 0.464844882
  266.           RND(0)    -> 0.0156260729
  267.  
  268.  
  269. Logic & Binary Operators:
  270.  
  271. Recall the encoding of Boolean Values:
  272.   FALSE <--> 0 (0x0000) and TRUE <--> -1 (0xFFFF) or any non-zero value
  273.  
  274. AND - Logical & Binary AND
  275.   Syntax: <Expr> AND <Expr>
  276.   Example: A>5 AND X<=Y
  277.          12 AND 10 -> 8 (%1100 AND %1010 = %1000)
  278.  
  279. OR - Logical & Binary OR
  280.   Syntax: <Expr> OR <Expr>
  281.   Example: A>5 OR X<=Y
  282.          12 OR 10 -> 14 (%1100 OR %1010 = %1110)
  283.  
  284. NOT - Logical & Binary NOT
  285.   Syntax: NOT <Expr>
  286.   Example: NOT A>5
  287.          NOT 2 -> -3 (NOT $0002 = $FFFD)
  288.  
  289.  
  290. Character & String Processing:
  291.  
  292. + - Concatenate Strings
  293.   Example: "Pow" + "er64" -> "Power64"
  294.  
  295. <, <=, =, <>, >=, > - Comparison Operators
  296.   Examples: "C64" < "Power64" -> -1 (TRUE)
  297.           "Alpha" > "Omega" -> 0  (FALSE)
  298.  
  299. LEN - Stringlength
  300.   Syntax: LEN(<String>)
  301.   Example LEN("Power64") -> 7
  302.  
  303. LEFT$ - Left part of a string
  304.   Syntax: LEFT$(<String>, <Len>)
  305.   Example: LEFT$("Power64", 5) -> "Power"
  306.  
  307. RIGHT$ - Right part of a string
  308.   Syntax: RIGHT$(<String>, <Len>)
  309.   Example: RIGHT$("Power64", 5) -> "wer64"
  310.  
  311. MID$ - Middle part of a string
  312.   Syntax: MID$(<String>, <Start>, <Len>)
  313.   Example: MID$("Power64 for Macintosh", 13, 3) -> "Mac"
  314.             /* 123456789012345678901 */
  315.  
  316. STR$ - Convert a Number into a String
  317.   Syntax: STR$(<Value>)
  318.   Example: STR$(6.25)  -> " 6.25"
  319.          STR$(-6.25) -> "-6.25"
  320.  
  321. VAL - Convert a String to a Number
  322.   Syntax: VAL(<String>)
  323.   Examples: VAL("6.25")  -> 6.25
  324.           VAL("6xx25") -> 6
  325.           VAL("x6x25") -> 0
  326.  
  327. ASC - ASCII code of the first character of a string
  328.   Syntax: ASC(<String>)
  329.   Examples: ASC("P") -> 80
  330.           ASC("Power64") -> 80
  331.  
  332. CHR$ - Character with a specific ASCII code
  333.   Syntax: CHR$(<Value>)
  334.   Example: CHR$(80) -> "P"
  335.  
  336.  
  337. Memory Access:
  338.  
  339. PEEK - Read Byte from Memory
  340.   Syntax: PEEK(<Addr>)
  341.   Example: PEEK(53280) -> Current Frame Color
  342.  
  343. POKE - Write Byte to Memory
  344.   Syntax: POKE <Addr>, <Value>
  345.   Example: POKE 53280, 7 -> Yellow Frame
  346.  
  347. WAIT - Wait until a Byte in Memory has a specific value
  348.   Syntax: WAIT <Addr>, <Mask> [, <Invert>]
  349.     WAIT will halt the program until ((PEEK(<Addr>) EXOR <Invert>) AND <Mask>) != 0
  350.     If <Invert> is not specified it is assumed to be 0.
  351.   Example: WAIT 198, 255 -> Wait for a key in the key buffer.
  352.  
  353.  
  354. Interface to Assembler Programs:
  355.  
  356. SYS - System - Call a Assembler Program
  357.   Syntax: SYS <Addr> [, <Param> ...]
  358.   The number of parameters depends on the actual program called.
  359.  
  360. USR - User Command
  361.   Syntax: USR(<Param>)
  362.   Similar to SYS but the <Addr> is fixed to $0310 and the first and only <Param> is already evaluated and stored in FloatAccu1 (FAC1) when the Assembler Program is called. Less flexible than SYS and thus rarely used.
  363.  
  364.  
  365. Program Execution:
  366.  
  367. RUN - Start the BASIC Program
  368.   Syntax: RUN [<Line>]
  369.   If no <Line> is given, the program is started on its first line.
  370.   Example: RUN
  371.  
  372. STOP - Stops program execution
  373.   Syntax: STOP
  374.   STOP is similar to END, but prints the message BREAK IN <Line> when
  375.   executed.
  376.  
  377. END - End program execution
  378.   Syntax: END
  379.  
  380. CONT - Continue program execution
  381.   Syntax: CONT
  382.   When program execution has interrupted by STOP, END or the Run/Stop
  383.   key, the command CONT can be used to resume execution.
  384.  
  385.  
  386. Miscellaneous:
  387.  
  388. REM - Remark
  389.   Syntax: REM <Text>
  390.   Example: REM This line contains a comment
  391.  
  392. LIST - Display the listing of the current BASIC program
  393.   Syntax: LIST [<Line> | <From>- | -<To> | <From>-<To>]
  394.   Without argument, the entire program is listed.
  395.   Examples: LIST
  396.           LIST -40
  397.           LIST 100-200
  398.  
  399. NEW - Delete the current program and all variables from memory
  400.   Syntax: NEW
  401.   If the NEW command was accidentally issued, the deleted program can
  402.   be recovered by using the NEW Magician described in Section 7.2.
  403.  
  404. CLR - Delete all variables
  405.   Syntax: CLR
  406.  
  407. FRE - Free Memory
  408.   Syntax: FRE(<Dummy>)
  409.   Example: FRE(0) -> -26627 (immediately after Power-on)
  410.   Returns the number of Bytes free for BASIC programs as a signed 16 Bit integer. If the free memory exceeds 32KByte then a negative number (the actual number of free Bytes - 65536) will be returned. Thus -26627 should be read as 65536-26627 = 38909.
  411.  
  412. ╧Ç   - Pi = 3.14159265
  413.  
  414. TI  - Timer Ticks since Power-On (1 Tick = 1/60 Second)
  415. TI$ - Timer since Power-On in Hour/Minute/Second Format
  416.       TI$ (but not TI) can be assigned a value!
  417.       The accuracy of the Timer is very poor (>1% drift)